package com.atguigu.controller;

import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.deepseek.DeepSeekAssistantMessage;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.ai.deepseek.DeepSeekChatOptions;
import org.springframework.ai.deepseek.api.DeepSeekApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Demo3_DeepSeekReasonerExampleController {

    private final DeepSeekChatModel chatModel;

    @Autowired
    public Demo3_DeepSeekReasonerExampleController(DeepSeekChatModel chatModel) {
        this.chatModel = chatModel;
    }
    @RequestMapping(value = "/ai/generateReasoner")
    public String deepSeekReasonerExample1(@RequestParam(defaultValue = "9.11 和 9.8, 哪个更大?") String message) {
        DeepSeekChatOptions promptOptions = DeepSeekChatOptions.builder()
                .model(DeepSeekApi.ChatModel.DEEPSEEK_REASONER.getValue())
                .build();
        Prompt prompt = new Prompt(message, promptOptions);
        ChatResponse response = chatModel.call(prompt);

        // Get the CoT content generated by deepseek-reasoner, only available when using deepseek-reasoner model
        DeepSeekAssistantMessage deepSeekAssistantMessage = (DeepSeekAssistantMessage) response.getResult().getOutput();
        String reasoningContent = deepSeekAssistantMessage.getReasoningContent();
        return deepSeekAssistantMessage.getText();
    }
}
